package com.competition.web.admin.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.competition.web.admin.mapper.LogContentMapper;
import com.competition.web.admin.service.ILogContentService;
import com.basic.service.impl.BaseServiceImpl;
import com.competition.web.entity.LogContent;
import com.competition.web.entity.LogContentWithBLOBs;
import com.security.admin.security.util.JwtTokenUtil;

@Service
public class LogContentServiceImpl extends BaseServiceImpl<LogContentWithBLOBs> implements ILogContentService {

	private JwtTokenUtil jwtTokenUtil;

	private RedisTemplate<String, Object> redisTemplate;
	

	@Autowired
	public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	final int CERTIFICATE_CLASSIFICATION = 1;
	
	
	public LogContentServiceImpl(LogContentMapper mapper) {
		super(mapper);
	}



	protected void insertPropteris(LogContent data) {

		long time =  (System.currentTimeMillis() / 1000);

		data.setCreateTime(time);
	}




//	public LogContentWithBLOBs selectByPrimaryKey(int id) {
//
//		String key = RedisConstant.getCertificateKey(id);
//
//		ValueOperations<String, Object> valueOperations = this.redisTemplate.opsForValue();
//
//		LogContentWithBLOBs certificateInfo = (LogContentWithBLOBs) valueOperations.get(key);
//
//		if (null != certificateInfo) {
//			return certificateInfo;
//		}
//
//		certificateInfo = super.selectByPrimaryKey(id);
//
//		if (null == certificateInfo) {
//			certificateInfo = new LogContentWithBLOBs();
//		}
//
//		valueOperations.set(key, certificateInfo, 5, TimeUnit.SECONDS);
//
//		return certificateInfo;
//
//	}
	
//	protected TableComment getTableComment(String tableName) {
//		
//		String key = RedisConstant.getTableCommentKey(tableName);
//
//		ValueOperations<String, Object> valueOperations = this.redisTemplate.opsForValue();
//
//		TableComment tableComment = (TableComment) valueOperations.get(key);
//
//		if (null != tableComment) {
//			return tableComment;
//		}
//
//		tableComment = this.mapper.getTableComment(tableName);
//
//		if (null == tableComment) {
//			tableComment = new TableComment();
//		}
//
//		valueOperations.set(key, tableComment, 50, TimeUnit.SECONDS);
//
//		return tableComment;
//		
//	}
	

//	@Override
//	public int insertParse(LogContent log, String tableName, Byte type) {
//		
//		TableComment comment = this.getTableComment(tableName);
//		
//		log.setComment(comment.getTableComment());
//		
//		log.setType(type);
//		
//		log.setTableName(tableName);
//
//		log.setId(0L);
//		
//		ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//		HttpServletRequest request = attributes.getRequest();
//		
//		String token = request.getHeader("Authorization");
//		
//		log.setAdminId(jwtTokenUtil.getId(token));
//		
//		log.setIp(RequestUtil.getRequestIp(request));
//		
//		return this.insert(log);
//	}

	public JwtTokenUtil getJwtTokenUtil() {
		return jwtTokenUtil;
	}

	public void setJwtTokenUtil(JwtTokenUtil jwtTokenUtil) {
		this.jwtTokenUtil = jwtTokenUtil;
	}

	@Override
	public List<LogContent> getLogContent(int logId) {
		
		LogContentMapper logMapper = this.getBaseMapper();
		
		return logMapper.getLogContent(logId);
	}

}